import wanlshop_config from '@/common/config/config';
let url = wanlshop_config.vehicleurl
// console.log(wanlshop_config.vehicleurl)
// if (process.env.NODE_ENV === 'development') {
// 	console.log('开发环境')
// 	url = 'http://ddcar.yljkapp.com'
// } else {
// 	console.log('生产环境')
// 	url = "http://ddcar.yljkapp.com"
// }

export const baseUrl = url;
let whiteArr = []
// console.log()
export function http(url, data, method = 'GET') {
	// console.log('请求参数', data);
	// console.log('token', uni.getStorageSync('token'));
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl + url,
			data,
			header: {
				'content-type': 'application/x-www-form-urlencoded',
				'token': uni.getStorageSync('token') || '',
				'type':'tst'
			},
			method,
			success: (res) => {
					// console.log(res)
				if (res.statusCode == 200) {
					if (res.res.code == 1) {
						resolve(res.data)
					} else if (res.res.code == 0) {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						reject(res.msg)
					} 
				}else if (res.res.code == 401) {
						let pages = getCurrentPages();
						var currPage = pages[pages.length - 1]; //当前页面
						let url = '/' + currPage.route;
						
						//登陆过期
						uni.showToast({
							title: "登录过期",
							icon: 'none'
						})
						uni.removeStorageSync('userInfo')
						uni.removeStorageSync('token')
						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/user/auth/name?url=' + url
							})
						}, 800)
					} else {
					uni.showToast({
						title: "接口请求失败" + res.statusCode,
						icon: 'none'
					})
				}
			},
			fail: (res) => {
				// uni.showToast({
				// 	title: '服务器请求异常',
				// 	icon: 'none'
				// })
			},
			complete: () => {

			}
		});
	})
}
